/*7idZsU/oE6l6KevOgbVClhp0fWrPiVbkPAMVwuH6DloTVI9t5r3iZffMaAEGEvzq*/
/*
 * @Author: guoylei 
 * @PageInfo: 打开草稿
 * @Date: 2021-07-13 15:17:31 
 * @Last Modified by: guoylei 
 * @Last Modified time: 2021-07-13 15:17:31 
 */
import { changeUrlParam, setDefData } from '../../../../../scmpub/scmpub/pub/cache';
import { UISTATUS, FIELDS, AREA, BUTTONID, DATASOURCECACHE, TEMPSAVECONFIG } from '../../constance';
import { buttonControl } from '../viewControl/buttonControl';

export default function temporaryClick(props, tempdata) {
	let empty = {
		value: null,
		display: null,
		scale: '-1'
	};
	//this.setState({ status: UISTATUS.edit });
	//设置页面状态
	buttonControl.call(this, this.props, UISTATUS.add);
	changeUrlParam(this.props, { status: UISTATUS.add, tempstatus: UISTATUS.add });
	let pk_org_v = null;
	//清空主键和表头
	this.props.form.setFormItemsValue(AREA.cardFormId, { [FIELDS.pk_ct_pu]: empty });
	this.props.form.EmptyAllFormValue(AREA.cardFormId);

	if (!tempdata) {
		this.props.initMetaByPkorg(FIELDS.pk_org_v);
	}

	//清空表体数据
	this.props.cardTable.setTableData(AREA.cardTableId, { rows: [] }); //表体
	this.props.cardTable.setTableData(AREA.cardTermId, { rows: [] }); //合同条款区
	this.props.cardTable.setTableData(AREA.cardPayId, { rows: [] }); //付款协议
	this.props.cardTable.setTableData(AREA.cardFeeId, { rows: [] }); //合同费用
	this.props.cardTable.setTableData(AREA.cardMemoraId, { rows: [] }); //合同大事记
	this.props.cardTable.setTableData(AREA.cardChangeId, { rows: [] }); // 变更历史
	this.props.cardTable.setTableData(AREA.cardExecutId, { rows: [] }); // 执行过程

	// 暂存
	if (tempdata) {
		setDefData(DATASOURCECACHE.tempCardCacheKey, TEMPSAVECONFIG.tempsave, true);
		let billcodeStr = tempdata.head[AREA.cardFormId].rows[0].values.vbillcode.value;
		//设置表头表体数据
		this.props.form.setAllFormValue({ [AREA.cardFormId]: tempdata.head[AREA.cardFormId] });
		if (tempdata.bodys) {
			this.props.cardTable.setTableData(AREA.cardTableId, tempdata.bodys[AREA.cardTableId], null, true, true);
			this.props.cardTable.setTableData(AREA.cardTermId, tempdata.bodys[AREA.cardTermId], null, true, true);
			this.props.cardTable.setTableData(AREA.cardPayId, tempdata.bodys[AREA.cardPayId], null, true, true);
			this.props.cardTable.setTableData(AREA.cardFeeId, tempdata.bodys[AREA.cardFeeId], null, true, true);
			this.props.cardTable.setTableData(AREA.cardMemoraId, tempdata.bodys[AREA.cardMemoraId], null, true, true);
			this.props.cardTable.setTableData(AREA.cardChangeId, tempdata.bodys[AREA.cardChangeId], null, true, true);
			this.props.cardTable.setTableData(AREA.cardExecutId, tempdata.bodys[AREA.cardExecutId], null, true, true);
		}

		this.props.BillHeadInfo.setBillHeadInfoVisible({
			billCode: billcodeStr //修改单据号---非必传
		});
		let pkorgValue = tempdata.head[AREA.cardFormId].rows[0].values.pk_org_v.value;
		if (pkorgValue) {
			pk_org_v = pkorgValue;
			this.props.resMetaAfterPkorgEdit();
		}
	}
	//设置暂存按钮可用
	this.props.button.setDisabled({ [BUTTONID.TemporaryStorage]: false });
}

/*7idZsU/oE6l6KevOgbVClhp0fWrPiVbkPAMVwuH6DloTVI9t5r3iZffMaAEGEvzq*/